package com.niit.service.impl;

import com.niit.dao.INewsDao;
import com.niit.dao.IProductDao;
import com.niit.dao.impl.NewsDaoImpl;
import com.niit.dao.impl.ProductDaoImpl;
import com.niit.domain.Product;
import com.niit.service.IProductService;
import domain.PageBean;

import java.util.List;

public class ProductServiceImpl implements IProductService {
    @Override
    public List<Product> productService(Integer page) {
        IProductDao iProductDao=new ProductDaoImpl();
        List<Product> list=iProductDao.queryProduct(page);
        return list;
    }

    @Override
    public List<Product> Is_goodService(Integer page) {
        IProductDao iProductDao1=new ProductDaoImpl();
        List<Product> list=iProductDao1.queryByIs_good(8);
        return list;
    }

    @Override
    public List<Product> Is_goodService2(Integer page) {
        IProductDao iProductDao2=new ProductDaoImpl();
        List<Product> list=iProductDao2.queryByIs_good2(4);
        return list;
    }

    @Override
    public PageBean<Product> queryProductsService(Integer currentPage, Integer pageSize) {
        IProductDao iProductDao = new ProductDaoImpl();
        domain.PageBean<Product> pageBean =new PageBean<Product>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);

        int Count = iProductDao.queryTotal();
        pageBean.setTotalCount(Count);

        int totalPage = Count % pageSize == 0 ? Count / pageSize :(Count / pageSize) + 1 ;
        pageBean.setTotalPage(totalPage);

        currentPage=(currentPage-1)*pageSize;
        pageBean.setList(iProductDao.queryProducts(currentPage,pageSize));
        return pageBean;
    }

    @Override
    public Product queryProductByIDService(Integer id) {
        IProductDao iProductDao = new ProductDaoImpl();
        Product product = iProductDao.queryProductByID(id);
        return product;
    }

    @Override
    public int productClickNum(Integer id) {
        IProductDao iProductDao = new ProductDaoImpl();
        int i = iProductDao.productsCountadd(id);
        return i;
    }
}
